package com.cskaoyan.shopping.converter;

import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dto.PanelContentItemDto;
import com.cskaoyan.shopping.dto.PanelDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.ArrayList;

/**
 * @author 22674
 * @version 1.0
 * @description: TODO
 * @date 2022/8/26 22:01
 */
@Mapper(componentModel = "spring")
public interface PanelConverter {

    @Mappings({@Mapping(source ="panelContent.id" ,target="id"),
            @Mapping(source ="panelContent.panelId",target = "panelId"),
            @Mapping(source ="panelContent.type",target = "type"),
            @Mapping(source ="panelContent.productId",target = "productId"),
            @Mapping(source ="panelContent.sortOrder",target = "sortOrder"),
            @Mapping(source ="panelContent.fullUrl",target = "fullUrl"),
            @Mapping(source ="panelContent.picUrl",target = "picUrl"),
            @Mapping(source ="panelContent.picUrl2",target = "picUrl2"),
            @Mapping(source ="panelContent.picUrl3",target = "picUrl3"),
            @Mapping(source ="panelContent.created",target = "created"),
            @Mapping(source ="panelContent.updated",target = "updated"),
            @Mapping(source ="item.title",target = "productName"),
            @Mapping(source ="item.price",target = "salePrice")
    })
    PanelContentItemDto PanelToPanelContentItemDto(PanelContent panelContent, Item item);


    @Mappings({@Mapping(source ="list" ,target = "panelContentItems")})
    PanelDto PanelAndList(Panel panel, ArrayList<PanelContentItemDto> list);
}
